import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "../store/index";
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
 
  {
    path: '/home',
    name: 'home',
    component: () => import(/* webpackChunkName: "about" */ '../views/HomeView.vue'),
    children: [
      {
        path: '/users',
        name: 'users',
        component: () => import(/* webpackChunkName: "about" */ '../views/users.vue')
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import(/* webpackChunkName: "about" */ '../views/roles.vue')
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import(/* webpackChunkName: "about" */ '../views/rights.vue')
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import(/* webpackChunkName: "about" */ '../views/categories.vue')
      },
      {
        path: '/params',
        name: 'params',
        component: () => import(/* webpackChunkName: "about" */ '../views/params.vue')
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import(/* webpackChunkName: "about" */ '../views/goods.vue')
      },
      {
        path: '/goods/add',
        name: 'goodsAdd',
        component: () => import(/* webpackChunkName: "about" */ '../components/goodsAdd.vue'),
        meta:{parentPath:'/goods'}
      }
    ]
  }
]
const router = new VueRouter({
  routes
})
// 路由守卫
router.beforeEach((to, form, next) => {
  if (to.path == '/') {
    next()
  } else {
    if (store.getters.token) {
      next()
    } else {
      next('/')
    }
  }
})

export default router
